var ArmatureController = require('geoArmatureController');
/**
 * 可用于编辑器的龙骨动画播放信息
 */
var ArmatureAnimData = cc.Class({
    name: 'geoArmatureAnimData',

    properties: {
        animController: {
            default: null,
            type: ArmatureController,
            tooltip: '龙骨动画控制器（不设置则采用默认控制器）'
        },
        animName: {
            default: '',
            tooltip: '动画名称（留空则不做新的动画控制，维持之前的动画状态）'
        },
        animLoops: {
            default: -1,
            type: cc.Integer,
            tooltip: '动画播放次数（-1为无限循环，这种情况必须提供tween并以tween作为结束类型）'
        },
        animFadeIn: {
            default: 0,
            type: cc.Float,
            tooltip: '动画融合时间'
        },
        animDisplayControl: {
            default: false,
            tooltip: '动画是否控制显示对象'
        },
        animCompleteEvents: {
            default: [],
            type: [cc.Component.EventHandler],
            tooltip: '动画播放完毕回调'
        },
    },
    /**
     * 
     * @param {Function} complete 
     * @param {geoArmatureController} controller 
     * @param {cc.Event} event 
     */
    play(complete, controller, event) {
        var ac = controller || this.animController;
        var animState = null;
        //
        if (ac && this.animName != '') {
            animState = ac.fadeInAnim(
                this.animName, this.animFadeIn, this.animLoops,
                (() => {
                    cc.Component.EventHandler.emitEvents(this.animCompleteEvents, event, this);
                    complete && complete();
                }).bind(this),
                this.animDisplayControl);
        }
        //
        return animState;
    },
});

module.exports = ArmatureAnimData;